package cn.donting.jme.edit.ui.scenetree.meum;

import cn.donting.jme.edit.ui.scenetree.ClipBoard;
import cn.donting.jme.edit.ui.scenetree.SceneTreeNodeView;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;


/**
 * 场景树 的右键菜单
 */
public class TreeContextMenu extends ContextMenu {
    /**
     * 剪切版
     */
    private ClipBoard clipBoard;
    /**
     * view
     */
    private SceneTreeNodeView sceneTreeNodeView;


    public TreeContextMenu(SceneTreeNodeView sceneTreeNodeView) {
        this.clipBoard = new ClipBoard(sceneTreeNodeView);
        this.sceneTreeNodeView = sceneTreeNodeView;
        CopyMenuItem copyMenuItem = new CopyMenuItem();
        CutMenuItem cutMenuItem = new CutMenuItem();
        PasteMenuItem pasteMenuItem = new PasteMenuItem();
        DeleteMenuItem deleteMenuItem = new DeleteMenuItem();
        SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem();
        AddGeometryMenu addObjectMenuItem = new AddGeometryMenu();
        AddLightMenu addLightMenu = new AddLightMenu();
        add(copyMenuItem);
        add(cutMenuItem);
        add(pasteMenuItem);
        add(deleteMenuItem);
        add(separatorMenuItem);
        add(addObjectMenuItem);
        add(addLightMenu);
    }

    private void add(MenuItem menuItem) {
        getItems().add(menuItem);
    }

    @Override
    public void show(Node anchor, double screenX, double screenY) {
        for (MenuItem item : getItems()) {
            if (item instanceof AbsTreeMenuItem) {
                item.setDisable(!((AbsTreeMenuItem) item).isAvailable(clipBoard));
            }
        }
        super.show(anchor, screenX, screenY);
    }
}
